local skel = fk.CreateSkill {
  name = "emo__miaojian",
}

Fk:loadTranslationTable{
  ["emo__miaojian"] = "妙剑",
  [":emo__miaojian"] = "你使用【杀】时，可秘密选择此结算为刺【杀】或须弃牌的【冰】杀，被弃置牌的角色受到你造成的1点伤害。",

  ["#emo__miaojian-choice"] = "妙剑：你可以将使用的【杀】改为刺【杀】或须弃牌的【冰】杀",

  ["$emo__miaojian1"] = "谨以三尺神锋，代天行化，布令宣威。",
  ["$emo__miaojian2"] = "布天罡，踏北斗，有秽皆除，无妖不斩。",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.trueName == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    local choice = player.room:askToChoice(player, {
      choices = {"stab__slash", "ice__slash", "Cancel"}, skill_name = skel.name, prompt = "#emo__miaojian-choice"
    })
    event:setCostData(self, {choice = choice})
    return true -- 因为是秘密抉择，可以空发
  end,
  on_use = function (self, event, target, player, data)
    local choice = event:getCostData(self).choice
    if choice == "Cancel" then return end
    data.extra_data = data.extra_data or {}
    data.extra_data[skel.name] = choice
  end,
})

skel:addEffect(fk.CardEffectCancelledOut, {
  is_delay_effect = true,
  mute = true,
  priority = 0.001,
  can_trigger = function(self, event, target, player, data)
    return data.extra_data and data.extra_data[skel.name] == "stab__slash"
    and data.to == player and not player.dead and not player:isKongcheng()
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = "stab__slash_skill",
      prompt = "#stab__slash-discard:::"..data.card:toLogString(),
      cancelable = true,
    }) == 0 then
      data.isCancellOut = false
    else
      room:damage { from = data.from, to = player, damage = 1, skillName = skel.name }
    end
  end,
})

skel:addEffect(fk.DamageCaused, {
  is_delay_effect = true,
  mute = true,
  priority = 0.001,
  can_trigger = function(self, event, target, player, data)
    if target == player and data.by_user and not data.to:isNude() then
      local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
      if use_event == nil then return false end
      local use = use_event.data
      return use.extra_data and use.extra_data[skel.name] == "ice__slash"
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data:preventDamage()
    local to = data.to
    for _ = 1, 2 do
      if to:isNude() or to.dead then break end
      local card = room:askToChooseCard(player, {
        target = to,
        flag = "he",
        skill_name = "ice_damage_skill",
      })
      room:throwCard(card, "ice_damage_skill", to, player)
    end
    room:damage { from = player, to = to, damage = 1, skillName = skel.name }
  end,
})

return skel
